package com.cskaoyan.controller;/**
 * @author mj
 * @date 2022-12-29 14:00
 * @describe
 */

import com.cskaoyan.annotation.ExecutionCreateLog;
import com.cskaoyan.bean.common.BasePageInfo;
import com.cskaoyan.bean.common.BaseRespVo;
import com.cskaoyan.bean.common.CommonData;
import com.cskaoyan.bean.marketBean.MarketAdmin;
import com.cskaoyan.bean.marketBean.MarketLog;
import com.cskaoyan.bean.marketBean.MarketPermission;
import com.cskaoyan.bean.marketBean.MarketRole;
import com.cskaoyan.bean.vo.*;
import com.cskaoyan.service.MarketAdmin_MJ_Service;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.LinkedList;
import java.util.List;

/**
 * @author MJ 系统管理 管理员
 * @date 2022-12-29 14:00
 * @describe
 */

@RestController
@RequestMapping("admin")
public class MJMarketAdminController {
    @Autowired
    MarketAdmin_MJ_Service marketAdminMJservice;


    @RequestMapping("admin/list")
    public BaseRespVo list(BasePageInfo info,String username){

        //http://localhost:8083/admin/admin/list?page=1&limit=20&sort=add_time&order=desc
        CommonData<MJMarketAdminListBean> ListData  = new CommonData<>();
        try {
            ListData = marketAdminMJservice.list(info,username);
        }catch (Exception e){
            return BaseRespVo.exception("数据库异常");
        }
        return BaseRespVo.success(ListData);

    }

    @RequestMapping("role/options")
    public BaseRespVo option(){
        CommonData<MJMarketAdminOption> OptionData = new CommonData<>();
        try {
            OptionData = marketAdminMJservice.option();
        }catch (Exception e){
            return BaseRespVo.exception("数据库异常");
        }
        BaseRespVo<Object> objectBaseRespVo = new BaseRespVo<>();
        objectBaseRespVo.setErrmsg("成功");
        objectBaseRespVo.setErrno(0);
        objectBaseRespVo.setData(OptionData);
        return objectBaseRespVo;
    }

    @ExecutionCreateLog
    @RequestMapping("admin/create")
    public BaseRespVo adminCreate(@RequestBody MJMarketAdminCreateVO param){
         MJMarketAdminCreateVO result;
        try {
           result= marketAdminMJservice.adminCreate(param);
        }catch (Exception e){
            return BaseRespVo.exception("存在异常");
        }
        return BaseRespVo.okyjc(result);
    }
    @ExecutionCreateLog
    @RequestMapping("admin/update")
    public BaseRespVo adminUpdate(@RequestBody MarketAdmin param){
        MarketAdmin result;
        try {
             result = marketAdminMJservice.adminUpdate(param);
        }catch (Exception e){
            return BaseRespVo.exception("存在异常");
        }
        return BaseRespVo.okyjc(result);
    }

    @RequestMapping("role/update")
    public BaseRespVo roleUpdate(@RequestBody MarketRole param){
        MarketRole result;
        try {
            result = marketAdminMJservice.roleUpdate(param);
        }catch (Exception e){
            return BaseRespVo.exception("更新失败");
        }
        return BaseRespVo.okyjc(result);
    }
    @ExecutionCreateLog
    @RequestMapping("admin/delete")
    public BaseRespVo adminDelete(@RequestBody MarketAdmin param){
        MarketAdmin result;
        try {
            marketAdminMJservice.adminDelete(param);
        }catch (Exception e){
            return BaseRespVo.exception("删除失败");
        }
        BaseRespVo<Object> objectBaseRespVo = new BaseRespVo<>();
        objectBaseRespVo.setErrno(0);
        objectBaseRespVo.setErrmsg("删除成功");
        return objectBaseRespVo;
    }

@RequestMapping("role/delete")
public BaseRespVo roleDelete(@RequestBody MarketRole param){
        try {
            marketAdminMJservice.roleDelete(param);
        }catch (Exception e){
            return BaseRespVo.exception("删除失败");
        }
    BaseRespVo<Object> objectBaseRespVo = new BaseRespVo<>();
    objectBaseRespVo.setErrno(0);
    objectBaseRespVo.setErrmsg("删除成功");
    return objectBaseRespVo;
}

    @RequestMapping("log/list")
    public BaseRespVo adminLog(BasePageInfo info,String name){

        CommonData<MarketLog> result = new CommonData<>();
        try {
           result =marketAdminMJservice.adminLog(info,name);
        }catch (Exception e){
            return BaseRespVo.exception("查看失败");
        }
        return BaseRespVo.okyjc(result);
    }

    @RequestMapping("role/list")
    public BaseRespVo roleList(BaseRespVo info,String name){
        CommonData<MarketRole> result = new CommonData<>();
        try {
            result = marketAdminMJservice.roleList(info,name);
        }catch (Exception e){
            return BaseRespVo.exception("查看失败");
        }
        return BaseRespVo.okyjc(result);
    }

    @RequestMapping("role/create")
    public BaseRespVo roleCreate(@RequestBody MarketRole param){
        MarketRole result;
        try {
            result =marketAdminMJservice.roleInsert(param);
        }catch (Exception e){
            return BaseRespVo.exception("添加失败");
        }
        return  BaseRespVo.okyjc(result);
    }

}
